window.location.setHashParameter = function(key, value){
	querys = this.hash.split("&");
	for(i in querys){
		query = querys[i];
		try{
			if (query.indexOf(key) != -1){
				this.hash = this.hash.replace("&" + query, ''); 
			}
		}catch(e){
		
		}	
	}
	if(value != ""){
		this.hash=this.hash+"&" + key + "=" + value;
	}
}


window.location.toggleCSVHashParam = function(key, val){
	querys = this.hash.split("&");
	this.hash="";
	hash_str = ""
	found=false;
	set=true;
	for(i in querys){
		query = querys[i];
		if (query.indexOf(key+"=") != -1){
			found=true;
			query = query.replace("" + key + "=", ""); 
			inner_querys = query.split(",");
			new_query = "";
			if(inner_querys.length>0){
				for(i in inner_querys){
					inner_query=inner_querys[i];
					if(inner_query != val){
						new_query += inner_query + ",";
					}else{
						set=false;
					}
				}
			}
			if(set){
				new_query += val + ",";
			}
			if(new_query != ""){
				hash_str += "&" + key + "=" + new_query.substring(0, new_query.length - 1);
			}
		}else{
			if(query != "#"){
				hash_str += "&" + query;
			}
		}
	}
	if(!found){
		if(hash_str=="&"){
			hash_str="";
		}
		hash_str += "&" + key + "=" + val;
	}
	this.hash = hash_str;
	
	return set;
}


window.location.setHashField = function(key, val){
	querys = this.hash.split("&");
	hash_str = "";
	found=false;
	for (i in querys){
		query = querys[i];
		if(query.indexOf(key) != -1){
			hash_str += "&" + key + "=" + val;			
		}else{
			hash_str += "&" + query;
		}
		found=true;
	}
	
	if(this.hash.indexOf(key+"=") == -1){
		this.hash += "&" + key + "=" + val;
	}else{
		hash_str = ltrim(hash_str, "&");
		this.hash = hash_str;	
	}
}
window.location.hashValueForKey = function(key){
	querys = this.hash.split("&");
	for(i in querys){
		query = querys[i];
		if(query.indexOf(key)!=-1){
			val = query.replace(key + "=", "");
			return val;
		}
	}
	return null;
}
window.location.removeHashParam = function(key){
	querys = this.hash.split("&");
	hash_str = "";
	for(i in querys){
		query = querys[i];
		if(query.indexOf(key+"=") == -1 && query != "#"){
			hash_str += "&" + query;
		}
	}
	this.hash = hash_str;
}

